package com.hkts.management.unattended.poundroom.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.unattended.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.unattended.poundroom.service.IYbMutualPovouchService;
import com.hkts.management.unattended.poundroom.entity.YbMutualPovouch;

import java.util.List;

/**
 * @author zy
 * @since 2021-10-13
 */
@RestController
@RequestMapping("/mutual/ybMutualPovouch")
public class YbMutualPovouchController {
    private final Logger logger = LoggerFactory.getLogger(YbMutualPovouchController.class);

    @Autowired
    public IYbMutualPovouchService iYbMutualPovouchService;

    /**
     * 分页查询数据
     *
     * @param page            分页信息
     * @param ybMutualPovouch 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getYbMutualPovouchPageList")
    public Result<Object> getHontUserList(Page<YbMutualPovouch> page, YbMutualPovouch ybMutualPovouch) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iYbMutualPovouchService.selectPage(page, ybMutualPovouch)));
    }

    /**
     * 保存和修改公用的
     *
     * @param ybMutualPovouch 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualPovouchSave")
    public Result<Object> ybMutualPovouchSave(YbMutualPovouch ybMutualPovouch) {
        iYbMutualPovouchService.saveOrUpdate(ybMutualPovouch);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/ybMutualPovouchGetById")
    public Result<Object> ybMutualPovouchGetById(String id) {
        YbMutualPovouch byId = iYbMutualPovouchService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualPovouchDelete")
    public Result<Object> hontUserDelete(String id) {
        iYbMutualPovouchService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualPovouchBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iYbMutualPovouchService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    /**
     * 根据物料名称获取List<对象>
     *
     * @param name 物料名称
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/selectPovouchListBycInvName")
    public Result<Object> selectPovouchListBycInvName(String name) {
        List<YbMutualPovouch> ybMutualPovouches = iYbMutualPovouchService.selectList(name);
        return ResultUtil.data(ybMutualPovouches);
    }

    /**
     * 根据code获取对象
     *
     * @param code 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/ybMutualPovouchGetBycPOID/{code}")
    public Result<Object> ybMutualSovouchGetBycPOID(@PathVariable(value="code") String code) {
        YbMutualPovouch bycPOID = iYbMutualPovouchService.getBycPOID(code);
        return ResultUtil.data(bycPOID);
    }

}
